package April._26.homework.work2;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class AnnotationTest {
    @Review
    String name;
    String path;
    public static void main(String[] args) throws ClassNotFoundException {
        //获取字节码文件
        Class<?> aClass = Class.forName("April._26.homework.work2.AnnotationTest");
        //获取成员变量
        Field[] declaredFields = aClass.getDeclaredFields();
        //遍历
        for (Field declaredField : declaredFields) {
            boolean annotationPresent = declaredField.isAnnotationPresent(Review.class);
            if(annotationPresent){
                System.out.println( declaredField+" 使用了注解");
                //获取注解实例（注意结果要用注解类型接收）
                Review annotation = declaredField.getAnnotation(Review.class);
                //获取注解属性
                String comment = annotation.comment();
                System.out.println("comment = " + comment);
            }
        }
    }
}
